/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa036is.controllers;

import cz.muni.fi.pa036is.dto.LoginDTO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author jostri
 */
@Controller
public class LoginController {
	
	@RequestMapping(value = "/admin/login", method = RequestMethod.POST)
	public String login(
							@Validated @ModelAttribute("login") LoginDTO login,
							BindingResult result, ModelMap model,
							HttpSession session,
							HttpServletRequest request) {

		System.err.println(login.getUsername() 
				+ " " + login.getPassword());
		if("admin".equals(login.getUsername()) && "pass".equals(login.getPassword())) {
			session.setAttribute("isAdmin", true);
		}
		
		return "redirect:/admin/season/season";
	}
	
}
